<?php
/*
Template Name: Page w/ Graphic Menu
*/
?>

<?php get_header(); ?>

		<div id="container">
			<div id="content" role="main" class="one-column">

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

<h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>

<div class="topContent"><?php the_content('(continue reading...)'); ?></div>

<?php
 $pageposts = $wpdb->get_results("SELECT *	FROM $wpdb->posts WHERE post_parent = ".$post->ID."	AND post_type = 'page' ORDER BY menu_order", 'OBJECT');
 ?>


<?php if ($pageposts): ?>
 <?php foreach ($pageposts as $post): ?>
 <?php setup_postdata($post); ?>
<?php $countPosts = $countPosts + 1; ?>
<div style="width: 28%; float: left; display: block; margin: 2%;">
<?php if (get_post_meta($post->ID, "FeatureImage", true) !="") { ?>
	<?php print '<a href="' . get_permalink() . '" rel="bookmark" title="' . $post->post_title . '"><img src="' . get_post_meta($post->ID, 'FeatureImage', true) . '" border="0" alt="' . $post->post_title . '" style="width: 100%; border: 2px solid black;"></a>'; ?>
<?php } ?>

<h3><a href="<?php echo get_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php echo ($post->post_title); ?></a></h3>

<?php the_post_thumbnail(); ?>

<?php if (get_post_meta($post->ID, "BriefDescription", true) !="") { ?>
<ul style="margin: 15px;"><li>
	<?php print str_replace("\n", "</li><li>", get_post_meta($post->ID, "BriefDescription", true)); ?>
</li></ul><br />
<?php } else { ?>

<?php } ?>

<a href="<?php echo get_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">[find out more]</a>


<?php
 $pagepageposts = $wpdb->get_results("SELECT *	FROM $wpdb->posts WHERE post_parent = ".$post->ID."	AND post_type = 'page' ORDER BY menu_order", 'OBJECT');
 ?>

<?php if ($pagepageposts): ?>
<br /><br />
Available Products
<ul style="margin: 15px;">
 <?php foreach ($pagepageposts as $post): ?>
 <?php setup_postdata($post); ?>
	<li><a href="<?php echo get_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul><br />
<?php endif; ?>

</div>

<?php
if ($countPosts % 3 == 0) {
print '<div style="clear: both;"></div>';
}
?>

<?php endforeach; endif; ?>


  <span class="linkpages"><?php wp_link_pages(); ?></span>
<div class="cleared"></div>
</div> <!-- Closes topPost -->
<br/><small><?php edit_post_link('Edit this entry?','',''); ?></small>





<?php endwhile; ?>

<?php else : ?>

<div class="topPost">
  <h2 class="topTitle"><a href="<?php the_permalink() ?>">Not Found</a></h2>
  <div class="topContent"><p>Sorry, but you are looking for something that isn't here. You can search again by using <a href="#searchform">this form</a>...</p></div>
</div> <!-- Closes topPost -->

<?php endif; ?>

			</div><!-- #content -->
		</div><!-- #container -->

<?php get_footer(); ?>